/**
 * 
 */
package optimization.naturalOptimization.population.individual.pso;

import optimization.naturalOptimization.population.Population;

/**
 * Provides a particle for a double array search space.
 * 
 * @author Kevin Wagner
 * @version 1.0
 */
public abstract class DoubleArrayParticle extends Particle<double[]> {

	/**
	 * Creates a new particle for the given population.
	 * 
	 * @param parentPopulation
	 */
	public DoubleArrayParticle(Population parentPopulation) {
		super(parentPopulation);
		int dim = parentPopulation.getParentOptimization().getDimensionality();
		setPosition(new double[dim]);
		setVelocity(new double[dim]);
		setNeighborhoodBest(new double[dim]);
		setPersonalBest(new double[dim]);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * optimization.naturalOptimization.population.Particle#positionUpdate()
	 */
	protected void positionUpdate() {
		try {
			double[] newPos = math.VectorCalculations.vectorAddition(
					getVelocity(), getPosition());
			this.setPosition(newPos);
		} catch (Exception e) {
			getParentPopulation().getParentOptimization().pushError(e);
		}
	}

}
